using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace DocumentManagement
{
  /// <summary>
  /// Treleasereason Data Object Class
  /// </summary>
  public partial class DOTreleasereason
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Treleasereason releasereasonid
		/// </summary>
		public const string Rowreleasereasonid = "releasereasonid";

		/// <summary>
		/// The Table Column for the Treleasereason releasereason
		/// </summary>
		public const string Rowreleasereason = "releasereason";

		/// <summary>
		/// The Table Column for the Treleasereason description
		/// </summary>
		public const string Rowdescription = "description";

		/// <summary>
		/// The Table Column for the Treleasereason active
		/// </summary>
		public const string Rowactive = "active";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spTreleasereason_Create";
private const string m_StoredProcedureConstDelete = "spTreleasereason_Delete";
private const string m_StoredProcedureConstRetrieve = "spTreleasereason_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spTreleasereason_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spTreleasereason_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private int m_releasereasonid;
		private string m_releasereason;
		private string m_description;
		private bool m_active;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOTreleasereason> m_Treleasereasons = new List<DOTreleasereason>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOTreleasereason() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// releasereasonid
		/// </summary>
		/// <remarks>
		/// This property contains the Treleasereason releasereasonid
		/// </remarks>
		public int releasereasonid
		{
			get { return (this.m_releasereasonid); }
			set { this.m_releasereasonid = value; }
		}

		/// <summary>
		/// releasereason
		/// </summary>
		/// <remarks>
		/// This property contains the Treleasereason releasereason
		/// </remarks>
		public string releasereason
		{
			get { return (this.m_releasereason); }
			set { this.m_releasereason = value; }
		}

		/// <summary>
		/// description
		/// </summary>
		/// <remarks>
		/// This property contains the Treleasereason description
		/// </remarks>
		public string description
		{
			get { return (this.m_description); }
			set { this.m_description = value; }
		}

		/// <summary>
		/// active
		/// </summary>
		/// <remarks>
		/// This property contains the Treleasereason active
		/// </remarks>
		public bool active
		{
			get { return (this.m_active); }
			set { this.m_active = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOTreleasereason> Treleasereasons
	{
	  get { return m_Treleasereasons; }
	  set { m_Treleasereasons = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public DataSet Retrieve()
    {
      DataSet returnDS = new DataSet();
      sqlData = new SQLDataObject();
      sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + Rowreleasereasonid + "=" + this.releasereasonid);
      return returnDS;
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    public bool Update()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[Rowreleasereasonid].ToString() != "")
			this.releasereasonid = int.Parse(dr[Rowreleasereasonid].ToString());

		if (dr[Rowreleasereason].ToString() != "")
			this.releasereason = dr[Rowreleasereason].ToString();

		if (dr[Rowdescription].ToString() != "")
			this.description = dr[Rowdescription].ToString();

		if (dr[Rowactive].ToString() != "")
			this.active = bool.Parse(dr[Rowactive].ToString());
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOTreleasereason Treleasereason = new DOTreleasereason();
			
					if (dr[Rowreleasereasonid].ToString() != "")
			Treleasereason.releasereasonid = int.Parse(dr[Rowreleasereasonid].ToString());

		if (dr[Rowreleasereason].ToString() != "")
			Treleasereason.releasereason = dr[Rowreleasereason].ToString();

		if (dr[Rowdescription].ToString() != "")
			Treleasereason.description = dr[Rowdescription].ToString();

		if (dr[Rowactive].ToString() != "")
			Treleasereason.active = bool.Parse(dr[Rowactive].ToString());

            this.Treleasereasons.Add(Treleasereason);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
